<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>kubernetes</title>
    <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

    <script src="../vendors/jquery/dist/jquery.min.js"></script>
    <script src="../vendors/bootstrap/dist/js/bootstrap.js"></script>
    <script src="../vendors/bootstrap/extend/DT_bootstrap.min.js"></script>
	    <style>
        .ui-droppable{
            padding-top: 10px;
        }
       .ui-sortable{
           margin-left: 15px;
       }
    </style>
</head>
<body style="background-color: #f7f9fc">
<div style="clear: both;padding-top: 10px;padding-left: 20px">
<ul class="nav nav-tabs">
    <li role="presentation" class="active"><a  href="#tab_1_1">harbor</a></li>
    <li role="presentation"><a  href="#tab_1_2">nexus</a></li>
    <li role="presentation"><a  href="#tab_1_3">kubernetes</a></li>
</ul>

    <div class="tab-content" >
        <div id="tab_1_1" class="tab-pane active" style="height: 100%;">
            <div id="dropharbor" class="ui-droppable ui-sortable">
			<div class="row" style="width:100%">
  <div class="col-md-3">
  <div class="panel panel-default">

  <div class="panel-heading">摘要</div>
<div id="harborsummary">
  </div>
  
  </div></div>
  <div class="col-md-8">
      <div class="panel panel-default">

          <div class="panel-heading">热门镜像仓库</div>
          <div style="margin-left:15px">
  <table class="table">
  <thead><tr><th style="width: 50%;overflow: hidden;">镜像仓库名</th><th style="width: 50%;overflow: hidden;">下载次数</th></tr></thead>
  <tbody id="harborhotimage"></tbody>
  </table></div></div>
  </div>
</div>
            </div>
        </div>
        <div id="tab_1_2" class="tab-pane" style="height: 100%;margin-top: 10px">
            <div class="row">
                <div class="col-md-2"></div>
                <div class="col-md-8">
            <div class="panel panel-default">

                <div class="panel-heading">NEXUS</div>
            <div id="dropnexus" class="ui-sortable">

            </div>
            </div>
                   </div>
                <div class="col-md-2"></div>
            </div>
        </div>
        <div id="tab_1_3" class="tab-pane" style="height: 100%;margin-top: 10px">
            <div class="row">
                <div class="col-md-2"></div>
                <div class="col-md-8">
                    <div class="panel panel-default">

                        <div class="panel-heading">KUBEMETES</div>
            <div id="dropkubernetes" class="ui-droppable ui-sortable">
            </div>
                    </div>
                </div>
                <div class="col-md-2"></div>
            </div>
        </div>
    </div></div>
<script language="JavaScript">

    $(function () {
        kubernetesdataload()
		harbordataload()
		nexusdataload();
    })
    $(".nav-tabs a").click(function (e) {
        e.preventDefault();
        $(this).tab('show');
    });
	function nexusdataload()
	{
       var config={
            showCheckbox: false,
			ispagination:false,
            method:"get",
            queryParams: {},
            url: "/api/nexus/getall",
            columns: [
                { field: 'name', title: '仓库名称', width: 28 },
                { field: 'repoType', title: '类型', width: 17 },
                { field: 'resourceURI', title: '仓库地址', width: 55,formatter: function(rowData){
                    return "<a target='_blank' href="+rowData.resourceURI+">"+rowData.resourceURI+"</a>";
                } }

            ]
        }
		$("#dropnexus").dataGrid(config);
	}
	
	function harbordataload()
	{
	    $.ajax({
		    type:"get",
			 url:"/api/harbor/getsummary",
			 success:function(res){
			 	    res = JSON.parse(res);
					var str="";
					for(var item in res)
					{
					str+="<li class=\"list-group-item\"> <span class=\"badge\">"+res[item]+"</span>"+item+"</li>";
					}
			 $("#harborsummary").append("<ul class=\"list-group\">"+str+"</ul>")
			 }
		})
		$.ajax({
			type:"get",
			url:"/api/harbor/gethostimage/5",
			success:function(res){
                res=JSON.parse(res);
				var str="";
				for(var i=0;i<res.length;i++)
				{
				str+="<tr><td>"+res[i].name+"</td><td>"+res[i].count+"</td></tr>";
				}
				$("#harborhotimage").append(str);
			}
		})
		
	}
    //加载case主数据
    function kubernetesdataload() {
        var config = {
            showCheckbox: false,
            ispagination:false,
            method:"get",
            queryParams: {},
            url: "/api/replication/default",
            columns: [
                { field: 'name', title: '名称', width: 12 },
                { field: 'labels', title: '标签', width: 17 },
                { field: 'fullyLabeledReplicas', title: '实例', width: 17 ,formatter: function(rowData){
				return rowData.availableReplicas+"/"+rowData.replicas;
				}},
                { field: 'creationTimestamp', title: '创建时间', width: 19 },
                { field: 'image', title: '镜像地址', width: 28 },
                {
                    field: ' ', title: "", width: 7, formatter: function (rowData) {
                    return "<button id='lookhttp"+rowData.id+"' class=\"btn\"  aria-expanded=\"false\"  data-toggle=\"collapse\"  href=\"#collapse"+rowData.id+"\"  onclick=\"showtestitem(" + rowData.id + ",'"+rowData.name+"','"+rowData.namespace+"','"+rowData.labels+"','"+rowData.creationTimestamp+"',"+rowData.availableReplicas+","+rowData.replicas+",'"+rowData.image+"')\" title=\"\" ><span class=\"glyphicon glyphicon-menu-right\"></span></button>";
                }
                }

            ]
        }
$("#dropkubernetes").dataGrid(config);
    }
    //显示案例的子数据
    function showtestitem(id,name,namespace,labels,creationTimestamp,availableReplicas,replicas,image,type)
    {
        if(type=="show")
        {
            $("#collapse"+id).parent().remove();

        }else if($("#collapse"+id).length>0)
        {
            $("#collapse"+id).parent().remove();
            $("#lookhttp"+id).children("span").addClass("glyphicon-menu-right");
            $("#lookhttp"+id).children("span").removeClass("glyphicon-menu-down");
            var main = $(this.window.parent.document).find("#iframe");
            var thisheight = $(document).height() - 350;
            main.height(thisheight);
            return;
        }
        $("#lookhttp"+id).children("span").removeClass("glyphicon-menu-right");
        $("#lookhttp"+id).children("span").addClass("glyphicon-menu-down");
        $("#lookhttp"+id).parent().parent().parent().after("<tr><td style=\"width:600px\" colspan=\"10\"><div id=\"collapse"+id+"\"></div><div id=\"testconfigure"+id+"\" ></div><div id=\"servermonitor"+id+"\" ></div></td></tr>")

            $("#collapse"+id).before("<div class=\"panel panel-default\"><div class=\"panel-heading\"><h3 class=\"panel-title\"><strong>Detail</strong></h3>"+
    "</div><div class=\"panel-body\">"+
	"<div class=\"row\"><div class=\"col-md-6\"><strong>名称:</strong>"+name+"</div><div class=\"col-md-6\"></div></div>"+
		"<div class=\"row\"><div class=\"col-md-6\"><strong>所处集群:</strong>"+namespace+"</div><div class=\"col-md-6\"></div></div>"+
			"<div class=\"row\"><div class=\"col-md-6\"><strong>查询标签:</strong>"+labels+"</div><div class=\"col-md-6\"></div></div>"+
				"<div class=\"row\"><div class=\"col-md-6\"><strong>创建时间:</strong>"+creationTimestamp+"</div><div class=\"col-md-6\"></div></div>"+
					"<div class=\"row\"><div class=\"col-md-6\"><strong>镜像名称:</strong>"+image+"</div><div class=\"col-md-6\"></div></div>"+
      "</div>")
             $.ajax({
			 type:"get",
			 url:"/api/kuberservice/getitem/default/"+name,
			 success:function(res)
			 {
			    res = JSON.parse(res);
			             $("#testconfigure"+id).before("<div class=\"panel panel-default\"><div class=\"panel-heading\"><h3 class=\"panel-title\"><strong>Services</strong></h3></div><div class=\"panel-body\"><table class=\"table table-bordered\">"+
 "<tr><td><strong>名称</strong></td><td><strong>查询标签</strong></td><td><strong>容器IP</strong></td><td><strong>容器端口</strong></td><td><strong>所在机器端口</strong></td></tr>"+
 "<tr><td>"+res.name+"</td><td>"+res.lables+"</td><td>"+res.clusterIP+"</td><td>"+res.internalEndpoints+"</td><td>"+res.externalEndpoints+"</td></tr>"+
"</table></div></div>")
			 }
			 })
             var config = {
            ispagination: false,
            method:"get",
            queryParams: {},
            url: "/api/pod/getitem/default/"+name,
            columns: [
                { field: 'name', title: '名称', width: 13 },
                { field: 'status', title: '状态', width: 19 },
                { field: 'starttime', title: '创建时间', width: 25 },
				{ field: 'podIP', title: '容器IP', width: 23 },
                { field: 'hostIP', title: '宿主IP', width: 20 }
            ]
        }
		            $("#servermonitor"+id).before("<div class=\"panel panel-default\"><div class=\"panel-heading\"><h3 class=\"panel-title\"><strong>Pods</strong></h3></div><div class=\"panel-body\"><table class=\"table table-bordered\"></div><div class=\"panel-body\"><div id=\"kuberpods"+id+"\"></div></div></div>")
$("#kuberpods"+id).dataGrid(config);

        var main = $(this.window.parent.document).find("#iframe");
        var thisheight = $(document).height() + 200;
        main.height(thisheight);
    }

</script>
</body>
</html>